//
//  DYZLaunchCarsController.m
//  汽车项目实战
//
//  Created by 白白龙腾 on 16/8/18.
//  Copyright © 2016年 heima. All rights reserved.
//

#import "DYZLaunchCarsController.h"
#import "DYZLaunchCarsDiscountCell.h"
#import "DYZLaunchCarsRemarkCell.h"
#import "DYZLaunchCarsTransactionCell.h"
#import "DYZLaunchCarsGuideCell.h"
#import "DYZAppearanceColourController.h"
#import "DYZSelectCarSourceTypeController.h"
#import "DYZSelectBrandController.h"
#import "DYZSalesTerritoryController.h"
static NSString *cellid = @"cellid";
static NSString *discountCellid = @"discountCellid";
static NSString *transactionCellid = @"transactionCellid";
static NSString *remarkCellid = @"remarkCellid";
static NSString *GuideCellid = @"GuideCellid";
@interface DYZLaunchCarsController ()

//全局的装有数据的数组
@property (nonatomic , strong)NSArray *arrayCars;

@end

@implementation DYZLaunchCarsController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //取出表格多余的分割线
    self.tableView.tableFooterView=[[UIView alloc]init];
    //取消弹性效果
    self.tableView.bounces = NO;
    //设置nav上的右侧的提交按钮
    self.navigationItem.rightBarButtonItem  = [[UIBarButtonItem alloc]initWithTitle:@"提交" style:UIBarButtonItemStylePlain target:nil action:nil];
    //设置标题
    [self.navigationItem setTitle:@"发布车源"];

    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellid];
    //注册四种样式的XIB的cell
    [self.tableView registerNib:[UINib nibWithNibName:@"DYZLaunchCarsDiscountCell" bundle:nil] forCellReuseIdentifier:discountCellid];
    [self.tableView registerNib:[UINib nibWithNibName:@"DYZLaunchCarsTransactionCell" bundle:nil] forCellReuseIdentifier:transactionCellid];
    [self.tableView registerNib:[UINib nibWithNibName:@"DYZLaunchCarsRemarkCell" bundle:nil] forCellReuseIdentifier:remarkCellid];
    [self.tableView registerNib:[UINib nibWithNibName:@"DYZLaunchCarsGuideCell" bundle:nil] forCellReuseIdentifier:GuideCellid];
    //假数据
    NSArray *cars = @[@"类型",@"车型",@"颜色",@"销售区域",@"指导价",@"优惠",@"成交价",@"备注"];
    
    self.arrayCars = cars;
 
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 8;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSString *resultID;
    
    if (indexPath.row == 4) {
        resultID = GuideCellid;
        DYZLaunchCarsGuideCell *cell = [tableView dequeueReusableCellWithIdentifier:resultID forIndexPath:indexPath];
        cell.GuideLabel.text = self.arrayCars[indexPath.row];
        cell.priceLabel.text = @"38.2";
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        return cell;
        
    }else if (indexPath.row == 5) {
        
        resultID = discountCellid;
        DYZLaunchCarsDiscountCell *cell = [tableView dequeueReusableCellWithIdentifier:resultID forIndexPath:indexPath];
        cell.discountLabel.text = self.arrayCars[indexPath.row];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        return cell;
        
        
    }else if (indexPath.row == 6){
        resultID = transactionCellid;
        DYZLaunchCarsTransactionCell *cell = [tableView dequeueReusableCellWithIdentifier:resultID forIndexPath:indexPath];
        cell.transactionLabel.text = self.arrayCars[indexPath.row];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }else if (indexPath.row == 7){
        resultID = remarkCellid;
        DYZLaunchCarsRemarkCell *cell = [tableView dequeueReusableCellWithIdentifier:resultID forIndexPath:indexPath];
        //设置自动计算行高
        tableView.rowHeight = 180;
        tableView.cellLayoutMarginsFollowReadableWidth = YES;
        cell.remarkLabel.text = self.arrayCars[indexPath.row];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }else{
        resultID = cellid;
        
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellid forIndexPath:indexPath];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.textLabel.text = self.arrayCars[indexPath.row];
        return cell;
    }

}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    //      取消cell的选中状态
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
    if (indexPath.row == 0) {
        DYZSelectCarSourceTypeController *vc = [[DYZSelectCarSourceTypeController alloc]init];
        
        //vc.view.backgroundColor = [UIColor redColor];
        [self.navigationController pushViewController:vc animated:YES];
    }else if (indexPath.row == 1)
    {
        DYZSelectBrandController *bc = [[DYZSelectBrandController alloc]init];
        [self.navigationController pushViewController:bc animated:YES];
    }
    else if (indexPath.row == 2){
        DYZAppearanceColourController *ac = [[DYZAppearanceColourController alloc]init];
        [self.navigationController pushViewController:ac animated:YES];
    }else if (indexPath.row == 3){
        DYZSalesTerritoryController *ztc = [[DYZSalesTerritoryController alloc]init];
        [self.navigationController pushViewController:ztc animated:YES];
    }
}

@end
